home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 27.zip / BS1 part 27 / ImageMaster_d3.adf / piarc.lzh.parta / Macload.rexx < prev    next >
OS/2 REXX Batch file  |  1993-03-29  |  6KB  |  224 lines

  1. /*
  2.  * Macload.rexx
  3.  *
  4.  *  Original Code stolen from Black Belt's JPEG.rexx loader
  5.  *  Written by: John Gager
  6.  * Last Update: 01/03/93
  7.  *         For: Black Belt Systems image processing series IM, IM F/c, and IP.
  8.  * ---------------------------------------------------------------------------
  9.  *    Revision: 1.3
  10.  */
  11. call pragma('stack',20000);
  12.  
  13. /*
  14.  * open rexxsupport.library -- needed for some functions
  15.  */
  16. if ~show('L',"rexxsupport.library") then do
  17.   if addlib('rexxsupport.library',0,-30,0) then do
  18.       /* everything's ok */
  19.     end;
  20.   else do
  21.     say 'We Have A Library Problem, Unable To Load "rexxsupport.library"';
  22.     say 'Cannot operate Macload.rexx without this library - sorry!';
  23.     exit 10;
  24.     end;
  25.   end;
  26.  
  27. /*
  28.  * This will automatically direct the script to the proper
  29.  * software, if it is running.
  30.  */
  31. prtnme = 'IP_Port'; /* assume Image Professional */
  32. if show('P','IP_Port') = 0 then do
  33.   if show('P','IM_Port') = 0 then do
  34.     say "Can't find image processor's ARexx port!!!"; /* not running? */
  35.     say "This script requires IP, IM or IM F/c to run!";
  36.     exit(20);
  37.     end;
  38.   else do
  39.     prtnme = 'IM_Port'; /* That's the thing about assumptions... */
  40.     end;                 /* We make em, user's break em.          */
  41.   end;
  42.  
  43.   /*
  44.    * This code attempts to read a file called "picmdpath" from REXX:
  45.    * If it can't find it, the script will assume that the commands
  46.    * associated with this PI Module are in "c:". If the file exists,
  47.    * the script will look in the path that is specified in the file.
  48.    * If you create this file, you MUST put a complete, correct path
  49.    * in it; if the commands are in a sub-directory, you have to put
  50.    * the trailing slash on the path (like, device:dir/).
  51.    *
  52.    */
  53.   cmdpath = 'c:';
  54.   if open(fhandle,'rexx:picmdpath','read') then  /* open the file */
  55.     do
  56.       cmdpath = readln(fhandle);
  57.       call close(fhandle);  /* close the file    */
  58.     end
  59.  
  60. options;
  61. address;
  62.  
  63.   prevpath = 'ram:'; /* put user in ram to start with... */
  64.  
  65.   if show('C',macpath) = 1 then do
  66.     prevpath = getclip(macpath);
  67.     end;
  68.  
  69.   address(prtnme);
  70.   options results;
  71.   'current';
  72.   bufdata = result; /* get name of buffer, if there is one */
  73.   parse var bufdata bname ',' bnum ',' bx ',' by ',' btot ',' bmem ',' bparname ',' bparnum;
  74.   if bname ~= '<none>' then do
  75.     bufname = bname;
  76.     end;
  77.   if (length(bufname) > 4) then do
  78.     epos = pos('.mac',bufname,length(bufname)-4);
  79.     if epos ~= 0 then do
  80.       bufname = left(bufname,epos-1)
  81.       end
  82.     end;
  83.   'filerequest "'||prevpath||'","'||bufname||'","","Load MacPaint .MAC file"';
  84.   MACfile = result;
  85.   options;
  86.  
  87.   if MACfile = 'FR_CANCELLED' then do
  88.     address(prtnme);
  89.     'imtofront';
  90.     exit 0;
  91.     end;
  92.  
  93.   MACfile = expandfilename(MACfile);
  94.   thispath = gimmepath(MACfile);
  95.   call setclip(macpath,thispath);
  96.  
  97.   address command cmdpath||'Macload c "'||MACfile||'"';
  98.   if rc ~= 0 then do
  99.     if rc = 1 then do
  100.       address(prtnme);
  101.       'message Cannot open 'MACfile'!';
  102.       end
  103.     if rc = 2 then do
  104.       address(prtnme);
  105.       'message Could not read MacPaint header info!';
  106.       end
  107.     if rc = 3 then do
  108.       address(prtnme);
  109.       'message 'MACfile' is not a MacPaint .MAC file!';
  110.       end
  111.     exit 0; /* this is not a proper .MAC file */
  112.     end;
  113.  
  114.   address(prtnme);
  115.  
  116.   'imtofront'; /* show user the IM screen */
  117.   /* is there already a primary buffer??? */
  118.   options results;
  119.   'current';
  120.   bufdata = result;
  121.   options;
  122.  
  123.   parse var bufdata bname ',' bnum ',' bx ',' by ',' btot ',' bmem ',' bparname ',' bparnum
  124.   if bname ~= '<none>' then do
  125.     address(prtnme);
  126.   options results;
  127.   'askyn '||'"Replace Primary ['||bname||']" "New As Primary"'
  128.   prefs = result;
  129.   options;
  130.   address;
  131.   if prefs = 0 then do
  132.     address(prtnme);
  133.     'killbuff '||bnum; /* this kills the Primary Buffer */
  134.     address;
  135.     end;
  136.   end;
  137.  
  138.   /* New buffer is created at current resolution */
  139.   address(prtnme);
  140.   'autoredraw 0';
  141.   options results;
  142.   width = 576;
  143.   height = 720;
  144.   'newbuf '||width||' '||height;
  145.   if rc ~= 0 then do
  146.     "message Can't allocate buffer!";
  147.     'autoredraw 1';
  148.     exit 0
  149.     end
  150.   bnum = result;
  151.   options;
  152.   'newcurrent '||bnum;
  153.   'rename '||bnum||' 'gxname;
  154.   'autoredraw 1';
  155.   address;
  156.  
  157.   address(prtnme);
  158.   options results;
  159.   'jackin';
  160.   jackadr = result;
  161.   options;
  162.  
  163.   'lockimage '||bnum;
  164.   address command cmdpath||'Macload r '||jackadr||' "'||MACfile||'"';
  165.   'unlockimage '||bnum;
  166.  
  167.   address(prtnme);
  168.   'redraw';
  169.   address;
  170.  
  171.   exit 0;
  172.  
  173. /*
  174.  * gimmepath
  175.  *
  176.  * This takes the provided argument and sucks the path out of it, then
  177.  * returns that path to the caller, sans file name.
  178.  */
  179. gimmepath:
  180.   arg fullnamegx;
  181.     tempgx = reverse(fullnamegx);
  182.     lengx = length(fullnamegx);   /* get length of string */
  183.     slashdex = index(tempgx,'/'); /* first occurance of '/' from right */
  184.     colondex = index(tempgx,':');  /* first occurance of ':' from right */
  185.     seploc = 0; /* assumes current dir, no path supplied */
  186.     if slashdex ~= 0 then do /* we assume we are in a DIR */
  187.       seploc = (lengx - slashdex)+1;
  188.       end;
  189.     else do
  190.       if colondex ~= 0 then do /* we assume we are on a device */
  191.         seploc = (lengx - colondex)+1;
  192.         end;
  193.       end;
  194.   gxname = substr(fullnamegx,seploc+1); /* if you ever need it */
  195.   gxpath = left(fullnamegx,seploc);
  196.   return(gxpath);
  197.  
  198. /*
  199.  * Since this script can't be expected to know where the CD of the user
  200.  * is when this cmd is invoked, we have to check the path the user
  201.  * provides - if it's not specified right from a root, then we have
  202.  * to make it a complete specification from the root.
  203.  */
  204. expandfilename:
  205.   parse arg jfile;
  206.   if index(jfile,':') = 0 then do
  207.     curdir = pragma(D);
  208.     if right(curdir,1) ~= ':' then do
  209.       if right(curdir,1) ~= '/' then do
  210.         if curdir ~= '' then do
  211.           curdir = curdir || '/';
  212.           end;
  213.         end;
  214.       end;
  215.     jfile = curdir||jfile;
  216.     end;
  217.   return(jfile);
  218.  
  219. rvalue:
  220.   wordnum = c2d(readch(fhandle,1)) * 256;
  221.   wordnum = wordnum + c2d(readch(fhandle,1));
  222.   return wordnum;
  223.  
  224.